<link href="/public/front/page/css/jquery.pagination.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="/public/front/page/js/jquery.min.js"></script>
<script type="text/javascript" src="/public/front/page/js/jquery.pagination.min.js"></script>
<div class="row">
    <div class="col-md-12">
        <div class="box">
            <div class="box-header with-border">
                    <form class="form-inline" method="get" action="/nav">
                        <div class="form-group">
                            <label for="title">标题</label>
                            <input type="text" class="form-control" id="title" name="title" placeholder="网站标题" value="{{.title}}">
                        </div>
                        <div class="form-group">
                            <label for="category_id">导航分类</label>
                            <select class="form-control" id="category_id" name="category_id" >
                                <option value="" {{if eq .category_id ""}}selected{{end}}>所有分类</option>
                                <option value="0" {{if eq .category_id "0"}}selected{{end}}>公共分类</option>
                                {{range $i, $v := .CateList}}
                                    {{$id :=  $v.ID|NumToStr}}
                                    <option value="{{$v.ID}}" {{if eq $.category_id $id}}selected{{end}}>{{$v.Name}}</option>
                                {{end}}
                            </select>
                        </div>
                        <div class="form-group">
                            <label for="show_position">位置</label>
                            <select class="form-control" id="show_position" name="show_position"  >
                                <option value="" {{if eq .show_position ""}}selected{{end}}>所有位置</option>
                                <option value="0" {{if eq .show_position "0"}}selected{{end}}>不显示</option>
                                <option value="1" {{if eq .show_position "1"}}selected{{end}}>首页</option>
                                <option value="2"  {{if eq .show_position "2"}}selected{{end}}>列表</option>
                            </select>
                        </div>

                        <div class="form-group">
                            <label for="re">推荐位</label>
                            <select class="form-control" id="re" name="re" >
                                <option value="" {{if eq .re ""}}selected{{end}}>无</option>
                                {{range $i, $v := .ReList}}
                                    {{$id :=  $v.ID|NumToStr}}
                                    <option value="{{$v.ID}}" {{if eq $.re $id}}selected{{end}}>{{$v.Title}}</option>
                                {{end}}
                            </select>
                        </div>

                        <button type="submit" class="btn btn-default">搜索</button>

                        <div class="form-group">
                            <a href="/nav/add"><button type="button" class="btn btn-block btn-default">新增内容</button></a>
                        </div>
                        <div class="form-group">
                        <button type="button" class="btn btn-block btn-default" id="del">删除</button>
                        </div>
                    </form>

            </div>
            <!-- /.box-header -->
            <div class="box-body">
                <table class="table table-bordered">
                    <tbody><tr>
                        <th style="width: 10px"><input type="checkbox" name="checkLine"></th>
                        <th style="width: 10px">ID</th>
                        <th style="width: 400px">标题</th>
                        <th>分类</th>
                        <th>位置</th>
                        <th>推荐位</th>
                        <th>创建时间</th>
                        <th>修改时间</th>
                        <th>排序</th>
                        <th></th>
                    </tr>
                    {{range $i, $v := .list}}
                        <tr>
                            <td><input type="checkbox" name="ids[]" value="{{$v.ID}}"></td>
                            <td>{{$v.ID}}</td>
                            <td>{{$v.Title}}</td>
                            {{if eq $v.Cname ""}}
                                <td style="color: red">公共分类</td>
                            {{else}}
                                <td>{{$v.Cname}}</td>
                            {{end}}

                            {{if eq $v.ShowPosition 0}}
                                <td style="color: red">无</td>
                            {{else if eq $v.ShowPosition 1}}
                                <td style="color: green">首页</td>
                            {{else if eq $v.ShowPosition 2}}
                                <td style="color: #b35e14">列表</td>
                            {{end}}

                            {{if ne $v.Recommend ""}}
                                <td style="color: green">有</td>
                            {{else}}
                                <td style="color: red">无</td>
                            {{end}}
                            <td>{{$v.CreatedAt | TimeToDate}}</td>
                            <td>{{$v.UpdatedAt | TimeToDate}}</td>
                            <td>{{$v.Sort}}</td>
                            <td>
                                <a href="/nav/update/{{$v.ID}}" target="_blank"><span class="label label-primary">更新</span></a>
                                <a onclick="javascript:return confirm('确认删除?')" href="/nav/del/{{$v.ID}}"><span class="label label label-danger">删除</span></a>
                            </td>
                        </tr>
                    {{end}}
                    </tbody>
                </table>
            </div>
            <!-- /.box-body -->
            <div id="pagination" class="page fl"></div>
        </div>
    </div>
</div>

<script>
    $(function(){
        $(":checkbox[name='checkLine']").bind('click',function(){
            $(":checkbox").prop("checked",this.checked);
        });

        //批量处理
        $('#del').on("click", function () {
            var str = "";
            $("input[name='ids[]']:checked").each(function (index, item) {
                if ($("input[name='ids[]']:checked").length-1==index) {
                    str += $(this).val();
                } else {
                    str += $(this).val() + ",";
                }
            });
            if (str == ""){
                alert("请选择需要删除的内容！")
                return
            }
            if (confirm("确定删除")){
                $.post("/nav/del/all",{"ids":str},function (rs) {
                    if (rs == "true"){
                        location = location
                    }else{
                        alert("删除失败！")
                    }
                })
            }
        });
    });
</script>

<script type="text/javascript">
    $("#pagination").pagination({
        currentPage: {{.pages.current}},
        totalPage: {{.pages.pageNum}},
        isShow: true,
        count: 10,
        homePageText: "首页",
        endPageText: "尾页",
        prevPageText: "上一页",
        nextPageText: "下一页",
        callback: function(current) {
            window.location = "/nav/{{.data.cid}}?page="+current+"&title={{.title}}&category_id={{.category_id}}&show_position={{.show_position}}&re={{.re}}"
        }
    });
</script>